#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>

enum
{
    Success = 0,
    Div_Zero,
    Mod_Zero,
};

int exit_code = Success;

const char *CodeToErrString(int code)
{
    switch(code)
    {
        case Success:
            return "Success";
        case Div_Zero:
            return "Div Zero";
        case Mod_Zero:
            return "Mode Zero";
        default:
            return "unknow error";
    }
}

int Div(int x, int y)
{
    if(0 == y)
    {
        exit_code = Div_Zero;
        return -1;
    }
    else
    {
        exit(1);
    }
}

int main()
{
    printf("hello 111"); 
    sleep(2);

    _exit(3);

    int *p = NULL;
    while(1)
    {
        printf("I am a process, pid: %d\n", getpid());
        sleep(1);
        exit(123);
        //*p = 100; //野指针 
    }

    int result = Div(10, 0);
    printf("result: %d [%s]\n", result, CodeToErrString(exit_code));

    return exit_code;

    int errcode = 0;
    for(errcode = 0; errcode <= 255; errcode++)
    {
        printf("%d: %s\n", errcode, strerror(errcode));
    }
    printf("I am process, pid: %d, ppid: %d\n", getpid(), getppid());
    sleep(2);

    return 0;
}
